<template>
  <div style="height: 50px; line-height: 50px;border-bottom: 1px solid #ccc ;display: flex">
    <div style="width: 200px; padding-left: 30px;font-weight: bold;color: rgb(87, 142, 190)">后台管理</div>
    <div style="flex: 1"></div>

    <div style="width: 100px">
      <el-dropdown>
        <span class="el-dropdown-link">
          {{ user.username }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="$router.push('/person')">个人信息</el-dropdown-item>
          <!--          给组件绑定路由跳转事件，需不要加上 .native-->
          <el-dropdown-item @click.native="exits">退出系统</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

    </div>

  </div>
</template>

<script>
export default {
  name: "Header",
  methods: {
    exits() {
      //退出，清除用户信息
      sessionStorage.clear();//清除所有 sessionStorage
      // sessionStorage.removeItem("username");
      this.$router.replace('/login');
    }
  },
  data() {
    return {
      //取出用户信息，转化为对象形式
      user: JSON.parse(sessionStorage.getItem("user"))
    }
  }
}
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>
